-- weaken_slime
-- created by zhuangsl
-- 冈布奥主动技的削弱目标类技能

return {
    apply = function(source, target, skillId, round, para, extra)
        local effectRound = -1;
        if para[6] > 0 then
            effectRound = round + para[6] + 1;
        end

        -- 专属技能等级
        local level;
        extra = extra or {};
        if extra["level"] then
            level = tonumber(extra["level"]);
        else
            local prop = PropM.combine(source, "gain_slime_skill", para[1]);
            level = PropM.apply(prop, 0);
        end

        -- 威力
        local base = para[4];
        local force = para[5];

        -- 作用效果
        local value = base + force * level;

        -- 斯巴达专属加成
        local prop = PropM.combine(source, "battle_cry", 1);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end
        value = PropM.apply(prop, value);

        value = math.max(1, value);

        -- 如果是boss
        if target:isBoss() then
            if para[7] == 1 then
                effectRound = round + 1 + 1;
            elseif para[7] == 2 then
                value = math.modf(value / 2);
            end
        end

        local condition = {
            ["id"] = para[3],
            ["value"] = value,
            ["end_round"] = effectRound,
        };

        -- 如果不免疫该技能，附加状态
        if SkillM.immunitySkill(source, target, skillId) then
            SkillM.getSequence(target):immunity(source, target, skillId);
        else
            CombatStatusM.applyStatus(target, para[2], condition);
        end

        -- 返回作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), arr[2], tonumber(arr[3]), tonumber(arr[4]), tonumber(arr[5]), tonumber(arr[6]), tonumber(arr[7] or -1), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 专属技能等级
        local prop = PropM.combine(source, "gain_slime_skill", para[1]);
        local level = PropM.apply(prop, 0);

        -- 技能效果
        local base = para[4];
        local force = para[5];

        local value = base + force * level;

        -- 斯巴达专属加成
        prop = PropM.combine(source, "battle_cry", 1);
        value = PropM.apply(prop, value);

        desc = string.gsub(desc, "{weaken_slime}", value / 10);

        -- 回合数
        local round = para[6];
        desc = string.gsub(desc, "{round}", round);

        return desc;
    end,
};
